package com.wuwei.controller;

import com.wuwei.pojo.CommonResult;
import com.wuwei.pojo.Payment;
import com.wuwei.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @description: PaymentController <br>
 * @date: 2021/2/5 17:56 <br>
 * @author: wuwei666 <br>
 * @version: 1.0 <br>
 */
@RestController
@Slf4j
public class PaymentController {

    @Value("${server.port}")
    private String DEFAULT_PORT;

    @Autowired
    private PaymentService paymentService;

    @PostMapping("/payment/create")
    public CommonResult createPayment(@RequestBody Payment payment){
        Integer result = paymentService.createPayment(payment);
        log.info("******插入结果{}",result);

        if (result > 0){
            return new CommonResult(200,"插入数据库成功",result);
        }else {
            return new CommonResult(444,"插入数据库失败",null);
        }
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult queryPaymentById(@PathVariable("id") Long id){
        Payment result = paymentService.getPaymentById(id);
        log.info("******查询结果{}",result);
        log.info("******端口是：{}",DEFAULT_PORT);

        if (result != null){
            return new CommonResult(200,"查询成功，端口号为：" + DEFAULT_PORT,result);
        }else {
            return new CommonResult(444,"查询失败,查询id:" + id,null);
        }
    }

    @GetMapping("/hello/zipkin")
    public String helloZipkin(){
        return "hello zipkin" + "端口号： " + DEFAULT_PORT;
    }
}
